/**
* 作者: hwp
* 日期: 2025-05-12 17:24:34
* 备注: 联盟宝箱进度表
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionBoxInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionBoxInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 联盟id
	protected int boxId; // 当前宝箱Id (玩家所在的宝箱id)
	protected int totalNum; // 累计次数 (每个宝箱ID累计集满次数)
	protected int progress; // 进度值 (本期的进度值)
	protected String boxNumRecord = ""; // 每个宝箱的次数记录 (1,50,2,100,3,200 奇数-boxId,偶数-累计次数)
	protected long addValue; // 每日普通礼盒增长活跃
	protected long resetTime; // 重置时间

	public void reset() {
	}

	protected String getKey() {
		return "UnionBoxInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_box_info"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 联盟id
		obj.put("boxId", boxId); // 当前宝箱Id (玩家所在的宝箱id)
		obj.put("totalNum", totalNum); // 累计次数 (每个宝箱ID累计集满次数)
		obj.put("progress", progress); // 进度值 (本期的进度值)
		obj.put("boxNumRecord", boxNumRecord); // 每个宝箱的次数记录 (1,50,2,100,3,200 奇数-boxId,偶数-累计次数)
		obj.put("addValue", addValue); // 每日普通礼盒增长活跃
		obj.put("resetTime", resetTime); // 重置时间
		return obj;
	}

	public PBUnionBoxInfo.Builder takeInitBuilder() {
		PBUnionBoxInfo.Builder sb = PBUnionBoxInfo.newBuilder();
		if (totalNum != 0) {
			sb.setTotalNum(totalNum);
		}
		if (progress != 0) {
			sb.setProgress(progress);
		}
		return sb;
	}

	public PBUnionBoxInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUnionBoxInfo.Builder sb = PBUnionBoxInfo.newBuilder();
		if (isFieldUpdate("totalNum")) {
			sb.setTotalNum(totalNum);
		}
		if (isFieldUpdate("progress")) {
			sb.setProgress(progress);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public int getBoxId() {
		return boxId;
	}

	public void putBoxId(int boxId) {
		if (this.boxId != boxId) {
			this.boxId = boxId;
			updateRedisHashField(getKey(), "boxId", this.boxId);
		}
	}

	public void addBoxId(int value) {
		this.boxId += value;
		updateRedisHashField(getKey(), "boxId", this.boxId);
	}

	public int getTotalNum() {
		return totalNum;
	}

	public void putTotalNum(int totalNum) {
		if (this.totalNum != totalNum) {
			this.totalNum = totalNum;
			updateRedisHashField(getKey(), "totalNum", this.totalNum);
		}
	}

	public void addTotalNum(int value) {
		this.totalNum += value;
		updateRedisHashField(getKey(), "totalNum", this.totalNum);
	}

	public int getProgress() {
		return progress;
	}

	public void putProgress(int progress) {
		if (this.progress != progress) {
			this.progress = progress;
			updateRedisHashField(getKey(), "progress", this.progress);
		}
	}

	public void addProgress(int value) {
		this.progress += value;
		updateRedisHashField(getKey(), "progress", this.progress);
	}

	public JsonArray getBoxNumRecordArray() {
		if (this.boxNumRecord != null && this.boxNumRecord.length() > 0) {
			return new JsonArray(this.boxNumRecord);
		} else {
			return new JsonArray();
		}
	}

	public String getBoxNumRecord() {
		return boxNumRecord;
	}

	public void putBoxNumRecord(String boxNumRecord) {
		if (!this.boxNumRecord.equals(boxNumRecord)) {
			this.boxNumRecord = boxNumRecord;
			updateRedisHashField(getKey(), "boxNumRecord", this.boxNumRecord);
		}
	}

	public long getAddValue() {
		return addValue;
	}

	public void putAddValue(long addValue) {
		if (this.addValue != addValue) {
			this.addValue = addValue;
			updateRedisHashField(getKey(), "addValue", this.addValue);
		}
	}

	public void addAddValue(long value) {
		this.addValue += value;
		updateRedisHashField(getKey(), "addValue", this.addValue);
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

}